package com.team5101.controller;


import com.team5101.entity.NowFilm;
import com.team5101.service.IHotFsService;
import com.team5101.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/api/hot")
public class HotFsController {
        @Autowired
        private IHotFsService iHotFsService;

        @RequestMapping("/hotMoviesInfor")
        @ResponseBody
        public R selectMovies(){                        //查询所有的展示电影信息
            return R.ok(iHotFsService.selectMovies());
        }

        @RequestMapping("/seleUpdataHotMovie")
        @ResponseBody
        public R updataMovie(Integer fnId){             //查询要修改的电影信息
         return R.ok(iHotFsService.updataMovies(fnId));
        }

        @RequestMapping(value = "/updataHotMovie",method = RequestMethod.POST)
        @ResponseBody
        public R updata(NowFilm nowFilm){              //修改电影信息
                System.out.println(nowFilm);
                Integer updata = iHotFsService.updata(nowFilm);
          if (updata==1){
             return R.ok("修改成功");
          }
            return R.error();
        }

        @RequestMapping("/deleteMovie")
        @ResponseBody
        public R dele(Integer fnId) {               //删除电影信息
            if (iHotFsService.dele(fnId) != 1) {    //如果删除返回的值不等于1
                return R.error();                   //返回删除失败
            }
                return R.ok();                      //删除成功
        }

        @RequestMapping("/onepage")
        @ResponseBody
        public R sel(Integer currentPage){     //分页查询
            return R.ok(iHotFsService.selectOnePage(currentPage));
        }

        @RequestMapping("/vagueselect")
        @ResponseBody
        public R vaguesele(String fnName){   //模糊查询出电影信息
          return R.ok(iHotFsService.vaguesele(fnName));
        }

        @RequestMapping("/insertMovie")
        @ResponseBody
        public R insertMovie(NowFilm nowFilm){   //添加电影
            Integer integer = iHotFsService.insertMovie(nowFilm);
            if (integer==0){    //返回值为0.插入失败
                return R.error();
            }
                return R.ok();  //插入成功
        }

}
